using Framework;
using UnityEngine;
using UnityEngine.UI;

public partial class MainUI : UIWindowBase
{
    public override void SetParam(string name, object value)
    {
        base.SetParam(name, value);
    }
    protected override void OnPrepare()
    {
        base.OnPrepare();
        this.Window.SetWorking(this, true);
        GameEntry.Timer.Start(0.1f, () =>
        {
            this.Window.SetWorking(this, false);
        });
    }
    protected override void OnOpen()
    {
        base.OnOpen();
        this.Window.SetWorking(this, true);
        GameEntry.Timer.Start(1f, () =>
        {
            this.Window.SetWorking(this, false);
        });
    }
    protected override void OnClose()
    {
        base.OnClose();
        this.Window.SetWorking(this, true);
        GameEntry.Timer.Start(1f, () =>
        {
            this.Window.SetWorking(this, false);
        });
    }
    protected override void OnButtonClick(Button target)
    {
        base.OnButtonClick(target);
        if (target == this.btn_Button)
        {
            GameEntry.Audio.Play("Assets/Res/Audio/message.mp3", 0);
            GameEntry.Atlas.SetSprite(this.load_Image, "Assets/Res/Atlas/Icon/FoodIcons_Atlas_12.png", true);
            GameEntry.Atlas.SetSprite(this.Image_Image, "Assets/Res/Atlas/Icon/IconMap004_23.png", true, true);
            // GameEntry.AssetLoader.LoadAsset("Assets/Res/Atlas/Icon/FoodIcons_Atlas_12.png", result =>
            // {
            //     Debug.LogError(result.Asset.GetType().FullName);
            //     if (result.Asset is Sprite sp)
            //     {
            //         this.Image_load.sprite = sp;
            //     }
            // });
        }
        else if (target == this.close_Button)
        {
            Close();
        }
    }
    public override void OnSortingOrderChanged(int value, int oldValue)
    {
        base.OnSortingOrderChanged(value, oldValue);
        var insId = this.Window.Canvas.GetInstanceID();
        var effectDepth = this.Window.gameObject.GetComponentsInChildren<UGUIEffectDepthAdapter>(true);
        foreach (var item in effectDepth)
        {
            item.Execute();
        }
    }
}